package com.aw.guiguzi.module.setting.presenters

import com.aw.baselib.base.AwCommonPresenter
import com.aw.baselib.net.callback.AwApiCallback
import com.aw.guiguzi.bean.BasePageRspBean
import com.aw.guiguzi.bean.MsgItemBean
import com.aw.guiguzi.module.setting.views.MsgListView
import com.aw.guiguzi.net.observers.NetObCommon

/**
 * @author : hzw
 */
class MsgListPresent(private val mView: MsgListView.View) : AwCommonPresenter(),
    MsgListView.Presenter {
    override fun getMsgList(pageIndex: Int, isfilterUnRead: Boolean) {
        addIOSubscription<BasePageRspBean<MsgItemBean>>(
            NetObCommon.getMsgList(
                pageIndex,
                isfilterUnRead
            ), object : AwApiCallback<BasePageRspBean<MsgItemBean>>(mView, true, true) {
                override fun onSuccess(result: BasePageRspBean<MsgItemBean>) {
                    mView.getMsgListSuccess(result.total, result.list?: emptyList())
                }

                override fun onFail(code: Int, msg: String) {
                    super.onFail(code, msg)
                    mView.showMsg(msg)
                    mView.getMsgListFail(code, msg)
                }
            })
    }

    override fun msgRead(id: String?) {
        addIOSubscription(NetObCommon.msgRead(id), object : AwApiCallback<Any>(mView, true, true) {
            override fun onSuccess(result: Any) {
                mView.msgReadSuccess()
            }

            override fun onFail(code: Int, msg: String) {
                super.onFail(code, msg)
                mView.showMsg(msg)
                mView.getMsgListFail(code, msg)
            }
        })
    }
}